package system.struct;

/**
 * This implementation is used to describe each <i>Entry</i> in <i>Search
 * Log</i>
 * <p>
 * the quality of a log entry is defined as:
 * <p>
 * quality = frequency / [word count]
 * 
 * @author Jack
 * 
 */
public class LogEntry {
	int qIndex, freq;
	/** definition: quality = freq / [word count] */
	double quality;
	String query;

	/**
	 * Constructs a <tt>LogEntry</tt> using given <i>Query Index</i>,
	 * <i>frequency</i> and <i>Query String</i>
	 * 
	 * @param qIndex
	 *            <i>Query Index</i>
	 * @param freq
	 *            <i>frequency</i>
	 * @param query
	 *            <i>Query String</i>
	 */
	public LogEntry(int qIndex, int freq, String query) {
		this.qIndex = qIndex;
		this.freq = freq;
		this.query = query;
		this.calcQuality();
	}

	/**
	 * Returns <i>Query String</i>
	 * 
	 * @return <i>Query String</i>
	 */
	public String getQuery() {
		return query;
	}

	public String toString() {
		return qIndex + "\t" + freq + "\t" + quality + "\t" + query;
	}

	/**
	 * Calculate the quality of this <tt>LogEntry</tt>
	 */
	private void calcQuality() {
		int word = query.split(" ").length;
		this.quality = freq * 1.0 / word;
	}
}